<?php

namespace App\Models;


use App\Tool\Helper;

/**
 * App\Models\OcrBlood
 *
 * @property int $id
 * @property int|null $ocr_id 化验单id
 * @property int|null $user_id 用户id
 * @property string|null $wbc 白细胞数目（WBC）
 * @property string|null $neut 中性细胞数（NEUT#）
 * @property string|null $lym 淋巴细胞数（LYM）
 * @property string|null $mono 单核细胞（MONO#）
 * @property string|null $eo 嗜酸性粒细胞（EO#）
 * @property string|null $baso 嗜碱性粒细胞（BASO#）
 * @property string|null $neut_rate 中性细胞比率（NEUT%）
 * @property string|null $lym_rate 淋巴细胞比率（LYM%）
 * @property string|null $mono_rate 单核细胞比率（MONO%）
 * @property string|null $eo_rate 嗜酸性粒细胞比率（EO%）
 * @property string|null $baso_rate 嗜碱性粒细胞比率（BASO%）
 * @property string|null $rbc 红细胞（RBC）
 * @property string|null $hgb 血红蛋白（HGB）
 * @property string|null $hct 红细胞压积（HCT）
 * @property string|null $mcv 红细胞平均体积（MCV）
 * @property string|null $mchc 平均血红蛋白量（MCHC）
 * @property string|null $rdw_cv 红细胞分布宽度变异系数（RDW-CV)）
 * @property string|null $rdw_sd 红细胞分布宽度标准差（RDW-SD）
 * @property string|null $plt 血小板（PLT）
 * @property string|null $mpv 平均血小板体积（MPV）
 * @property string|null $pdw 血小板宽度（PDW）
 * @property string|null $pct 血小板压积（PCT）
 * @property string|null $p_lcr 大型血小板比率（P-LCR）
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @method static \Illuminate\Database\Eloquent\Builder|OcrBlood newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|OcrBlood newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|OcrBlood query()
 * @method static \Illuminate\Database\Eloquent\Builder|OcrBlood whereBaso($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrBlood whereBasoRate($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrBlood whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrBlood whereEo($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrBlood whereEoRate($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrBlood whereHct($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrBlood whereHgb($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrBlood whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrBlood whereLym($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrBlood whereLymRate($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrBlood whereMchc($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrBlood whereMcv($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrBlood whereMono($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrBlood whereMonoRate($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrBlood whereMpv($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrBlood whereNeut($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrBlood whereNeutRate($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrBlood whereOcrId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrBlood wherePLcr($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrBlood wherePct($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrBlood wherePdw($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrBlood wherePlt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrBlood whereRbc($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrBlood whereRdwCv($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrBlood whereRdwSd($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrBlood whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrBlood whereUserId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|OcrBlood whereWbc($value)
 * @mixin \Eloquent
 */
class OcrBlood extends Base{

    protected $table = 'ocr_blood';
    public $columnsArr = [
        'wbc' => '白细胞数目（WBC）',
        'neut' => '中性细胞数（NEUT#）',
        'lym' => '淋巴细胞数（LYM）',
        'mono' => '单核细胞（MONO#）',
        'eo' => '嗜酸性粒细胞（EO#）',
        'baso' => '嗜碱性粒细胞（BASO#）',
        'neut_rate' => '中性细胞比率（NEUT%）',
        'lym_rate' => '淋巴细胞比率（LYM%）',
        'mono_rate' => '单核细胞比率（MONO%）',
        'eo_rate' => '嗜酸性粒细胞比率（EO%）',
        'baso_rate' => '嗜碱性粒细胞比率（BASO%）',
        'rbc' => '红细胞（RBC）',
        'hgb' => '血红蛋白（HGB）',
        'hct' => '红细胞压积（HCT）',
        'mcv' => '红细胞平均体积（MCV）',
        'mchc' => '平均血红蛋白量（MCHC）',
        'rdw_cv' => '红细胞分布宽度变异系数（RDW-CV）',
        'rdw_sd' => '红细胞分布宽度标准差（RDW-SD）',
        'plt' => '血小板（PLT）',
        'mpv' => '平均血小板体积（MPV）',
        'pdw' => '血小板宽度（PDW）',
        'pct' => '血小板压积（PCT）',
        'p_lcr' => '大型血小板比率（P-LCR）',
    ];

    protected $fillable = [
    ];

//    public $timestamps = false;//关闭自动维护

    public function add($item)
    {
        $columnsArr = Helper::reverseArr($this->columnsArr);
        $insertItem = [];
        foreach ($item as $k => $value) {
            $insertItem[$columnsArr[$value['name']] ?? $value['name']] = $value['content'];
        }
        $insertItem['created_at'] = date('Y-m-d H:i:s');
        $insertItem['updated_at'] = $insertItem['created_at'];

        self::insert($insertItem);
    }

    /**
     * 编辑资料
     *
     * @param $id
     * @param $user_id
     * @param $data
     * @return false
     */
    public function edit($id, $user_id, $data)
    {
        $model = self::whereUserId($user_id)
            ->where('id', $id)
            ->first();
        if (empty($model)) return false;

        $model->wbc = $data['wbc'] ?? null;
        $model->neut = $data['neut'] ?? null;
        $model->lym = $data['lym'] ?? null;
        $model->mono = $data['mono'] ?? null;
        $model->eo = $data['eo'] ?? null;
        $model->baso = $data['baso'] ?? null;
        $model->neut_rate = $data['neut_rate'] ?? null;
        $model->lym_rate = $data['lym_rate'] ?? null;
        $model->mono_rate = $data['mono_rate'] ?? null;
        $model->eo_rate = $data['eo_rate'] ?? null;
        $model->baso_rate = $data['baso_rate'] ?? null;
        $model->rbc = $data['rbc'] ?? null;
        $model->hgb = $data['hgb'] ?? null;
        $model->hct = $data['hct'] ?? null;
        $model->mcv = $data['mcv'] ?? null;
        $model->mchc = $data['mchc'] ?? null;
        $model->rdw_cv = $data['rdw_cv'] ?? null;
        $model->rdw_sd = $data['rdw_sd'] ?? null;
        $model->plt = $data['plt'] ?? null;
        $model->mpv = $data['mpv'] ?? null;
        $model->pdw = $data['pdw'] ?? null;
        $model->pct = $data['pct'] ?? null;
        $model->p_lcr = $data['p_lcr'] ?? null;
        return $model->save();
    }
}
